<template>
	<view class="mainpadding">
		<view class="shilitu"  @click="uploadImg()">
			<image :src="userInfo.avatar_text" mode=""></image>
		</view>
		<view class="flexbetween margin_top mainpadding radius ffffff">
			<view class="titletext" style="min-width: 150rpx;">昵称</view>
			<input class="inputs" type="text" placeholder="请输入昵称" v-model="nickname">
		</view>
		<view class="flexbetween margin_top mainpadding radius ffffff">
			<view class="titletext" style="min-width: 150rpx;">联系方式</view>
			<input class="inputs" type="text" placeholder="请输入联系方式" v-model="lxfs">
		</view>
		<!-- 底部 -->
		<view class="gudingdb ffffff mainpadding">
			<view class="bigbtn" @click="submit">确认修改</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				userInfo: {},
				nickname:"",
				
				
				
				
				
				
				
				
				
				
				
				
				
				
				
				
				
				
				lxfs:"",
			}
		},
		onShow() {
			this.init()
		},
		methods: {
			init() {
				httpRequest.request('/api/user/index', 'GET', {}).then(res => {
					this.userInfo = res.data
					this.nickname = res.data.nickname || ""
					this.lxfs = res.data.lxfs || ""
				})
			},
			submit(){
				httpRequest.request('/api/user/profile', 'GET', {
					avatar:this.userInfo.avatar,
					nickname:this.nickname,
					lxfs:this.lxfs
				}).then(res => {
					httpRequest.toast(res.msg)
					if(res.code==1){
						setTimeout(()=>{
							uni.navigateBack(1)
						},1000)
					}
				})
			},
			uploadImg() {
				let _this = this;
				uni.showActionSheet({
					itemList: ['相机', '相册'],
					success: function(res) {
						// 选择相机走0
						if (res.tapIndex == 0) {
							httpRequest.chooseImage(1, ['camera']).then(res => {
								for (var i = 0; i < res.length; i++) {
									_this.uploadImageService(res[i])
								}
							}).catch(err => {});
						}
						// 选择相册走1
						if (res.tapIndex == 1) {
							httpRequest.chooseImage(1, ['album']).then(res => {
								for (var i = 0; i < res.length; i++) {
									_this.uploadImageService(res[i])
								}
							}).catch(err => {});
						}
					},
					fail: function(res) {}
				});
			},
			uploadImageService(url) {
				let _this = this;
				httpRequest.uploadFile('/api/common/upload', url).then(res => {
					this.userInfo.avatar = res.url
					this.userInfo.avatar_text = res.fullurl
				}).catch(err => {});
			},
		}
	}
</script>

<style lang="scss" scoped>
	.gudingdb {
		position: fixed;
		bottom: 0;
		width: 100%;
		left: 0;
		padding: 30rpx 30rpx 60rpx;
		box-sizing: border-box;
	}

	.inputs {
		width: 85%;
		text-align: right;
	}

	.huisetext {
		font-size: 24rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #666666;
	}

	.shilitu {
		margin: auto;
		width: 122rpx;
		height: 122rpx;
		border-radius: 50%;

		image {
			width: 122rpx;
			height: 122rpx;
			border-radius: 50%;
		}
	}
</style>